package user_private_key

import (
	"github.com/xinliangnote/go-gin-api/internal/pkg/core"
	"github.com/xinliangnote/go-gin-api/internal/repository/mongodb/operation_log"
	userModel "github.com/xinliangnote/go-gin-api/internal/repository/mongodb/user"
	"github.com/xinliangnote/go-gin-api/internal/repository/mongodb/user_private_key"
	"time"
)

func (s *service) Delete(ctx core.Context, id string) error {
	model := user_private_key.NewModel()

	err := model.Delete(s.db.GetDb(), id)

	userInfo := ctx.GetInfo("userInfo").(*userModel.User)
	logModel := operation_log.NewModel()
	logModel.FTable = "user_private_key"
	logModel.Type = "edit"
	logModel.FId = id
	logModel.IpAddr = ctx.GetClientIP()
	logModel.AdminName = userInfo.Username
	logModel.Content = "删除钱包:id[" + id + "]"
	logModel.Timestamp = time.Now().Unix()
	logModel.Create(s.db.GetDb())

	return err
}
